<!-- saved from url=(0016)http://localhost -->
var xml=loadXMLDoc("guncase.xml");
var xsl=loadXMLDoc("guncase.xsl");
var elemXPath=xsl.getElementsByTagName("xsl:for-each")[0];


//Display XML file transformed to XSL style
function displayResult(path)
{
	elemXPath.setAttribute("select",path);
	
	// code for IE
	if (window.ActiveXObject)
	{
		ex=xml.transformNode(xsl);
		document.getElementById("example").innerHTML=ex;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById("example").appendChild(resultDocument);
	}
}


//Load files create new request object
function loadXMLDoc(dname)
{	
	if (window.XMLHttpRequest)
	{
		xhttp=new XMLHttpRequest();
	}
	else
	{

		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;	
}

function createDropBox()
{
	// Select gun maker through dropbox	
	path="/guncase/gun/maker";
	if ( window.ActiveXObject )
	{
		var nodes=xml.selectNodes(path);
		var str = '<option value="all">All</option>'

		for ( var i=0;i<nodes.length;i++ )
		{
			str += '<option value="' + ( i ) + '">' + nodes[i].childNodes[0].nodeValue + "</options>";
		}
		document.getElementById( "pt" ).innerHTML= '<select id="stuff" onchange="table()">' + str + " </select>";
	}
}

function table()
{
    var num= document.getElementById("stuff");
    value = num.options[num.selectedIndex].value;
    indexUpdate(value);
}

function indexUpdate(index)
{
	var path="/guncase/gun/maker";
	var nodes=xml.selectNodes( path );

	if ( index>=0 && index<nodes.length )
	{	
	    path = "guncase/gun["+(parseInt(index)+1)+"]"
        displayResult(path)
	}
	else if ( index == "all")
	{
	    path="guncase/gun";
	    displayResult(path)
	}
}
